<?php
/**
 *蚂蚁预售
 *@author lxsy01@163.com 
 *@QQ 457178642
 *@2013-11-24
 */
class FruitAction extends Action
{
	const PAGE_SIZE = 32;
	const NO_MARKET_PRICE = 1.1;

	public function index()
	{
		$now_page = intval($this->_get('page'));
		$cid = intval($this->_get('cid'));
		if(empty($now_page)){
			$now_page = 1;
		}
		
		if(!empty($cid))  $options['cat_id'] = $cid;
		$page_size = self::PAGE_SIZE;
		
		$count = GoodsModel::getCount($options);

		$page = array(
			'count' => $count,
			'page_size' => $page_size,
			'now_page' => $now_page,
			);

		$goods = GoodsModel::getGoodsList(($now_page-1)*$page_size,$page_size,$options,array("uptime"=>"desc"));

		foreach($goods as &$v){
			if(empty($v['market_price']) || $v['market_price'] < $v['price']){
				$v['market_price'] = $v['price']*self::NO_MARKET_PRICE;
			}
			$v['discount'] = number_format(($v['price']/$v['market_price'])*10,1);//保留一位小数
		}
		//Ad
		$options['place_tag'] = 'fruit1';
		$this->top_ad = AdModel::getAdList($options);
		//分类
		$cate = CateModel::getCateByPid(24);

		$this->assign("page",$page);
		$this->assign("cid",$cid);
		$this->assign("cate",$cate);
		$this->assign("menu_width",intval(1238/(count($cate)+1)));
		$this->assign("goods",$goods);
		$this->assign("current_class",4);

		$this->goods_view=unserialize(stripslashes(cookie('goods_view')));
		$this->cat=R('Goods/goods_cat');
		$shop_cart=cookie('shopcart');
		$this->cart_num=!empty($shop_cart)?count(unserialize(stripslashes($shop_cart))):0;
		$this->assign("cat_now", $cat_now);
		$this->name= "蚂蚁预售-蚂蚁街";
		$this->user=$_SESSION['euname'];
		$this->assign("keyword",$key);
		$this->display();
	}

}